﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

using dnsServerCSharp;

namespace dnsServerCSharp
{
    class Program
    {
        static DnsMessage createDnsQueryMessage(string name)
        {
            DnsMessage msg = new DnsMessage();
            msg.header.id = 1;
            msg.header.isResponse = false;
            msg.header.opcode = DnsQueryType.Query;
            msg.header.authoritative = false;
            msg.header.truncation = false;
            msg.header.recursionDesired = true;

            msg.header.recursionAvailable = false;
            msg.header.reserved = false;
            msg.header.authenticatedData = false;
            msg.header.checkingDisabled = false;
            msg.header.responseCode = DnsResponseCode.NoError;

            var q = new DnsQuestion();
            q.name = name;
            q.dnsClass = DnsClass.Internet;
            q.recordType = DnsRecordType.A;
            msg.questions.Add(q);
            return msg;
        }
        static void Main(string[] args)
        {
            var banList = new Dictionary<System.Text.RegularExpressions.Regex, Boolean>();
            banList.Add(new System.Text.RegularExpressions.Regex("baidu.com"), true);

            Server s = new Server();
            Config.loadInto(s);

            Console.WriteLine("-------------------------------------");
            Console.WriteLine("Dns Server");
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("");
            Console.WriteLine("");

            Console.WriteLine("Filter number : {0}", s.filter.size);
            Console.WriteLine("Redirect DNS Server : {0}", s.redirectServerName);
            Console.WriteLine("Listening Port : {0}{1}", s.listeningPort, s.listeningPort == 53 ? " (default DNS port)" : "");
            Console.WriteLine("");
            Console.WriteLine("");

            if (s.start())
            {
                Console.WriteLine("Server startup ok!");
            }

            System.Windows.Forms.Application.Run();
        }
    }
}
